package com.luyou.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


/**
 * <a href="http://localhost:8080/demo_servlet_war/form/get?name=%E9%99%86%E6%B8%B8&url=www.luyou.com">例子</a>
 * 此处value = 必须/开头
 */
@WebServlet(name = "formGetServlet", value = "/form/get")
public class FormGetServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置响应内容类型
        resp.setContentType("text/html;charset=UTF-8");

        PrintWriter out = resp.getWriter();
        String title = "使用 GET 方法读取表单数据";

        String docType = "<!DOCTYPE html>";
        out.println(docType +
                "<title>" + title + "</title>" +
                "<p>" + title + "</p>" +
                "<ul>" +
                "  <li><b>站点名</b>："
                + req.getParameter("name") + "\n" +
                "  <li><b>网址</b>："
                + req.getParameter("url") + "\n" +
                "</ul>");
    }
    // 处理 POST 方法请求的方法
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doGet(request, response);
    }
}
